<?php defined('SYSPATH') OR die('No direct access allowed.');

	include('monday_fakty.php');

	$tab = $this->input->get();
	if(count($tab) >0)
	{
  $nr_sem=array_values($tab); 
  
  $file=fopen("io_dir/query.xml","w") or exit("Unable to open file!");
  
  fputs($file,"<?xml version=\"1.0\" encoding=\"utf-8\"?>");
  fputs($file,"\n");
  fputs($file,"<queries xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"monday1705.xsd\">");
  fputs($file,"\n");
  fputs($file," <query>\n  <coursesChoiceQuery>\n   <courses>\n");
     
	foreach ($tab as $item)
	{
	      fputs($file,"   <course>");
        fputs($file,substr($item,1,strlen($item)-1));
        fputs($file,"</course>\n");
  }
  fputs($file,"   </courses>\n");
  
  //ostatni semestr, na ktory bylo sie zapisanym
  fputs($file,"   <term>");
  fputs($file,$nr_sem[0][0]);
  fputs($file,"</term>\n");
  fputs($file,"  </coursesChoiceQuery>\n");
  fputs($file," </query>\n");
  fputs($file,"</queries>");
 
	echo '<p>'.Kohana::lang('core.stats_footer')."</p>\n";
  fclose($file);
	url::redirect(url::base()."pypublish/module.py");
	}
	else
	{
		echo "<img src=\"".url::base()."layout/lopata.jpg\"/>";
					
	}
?>
